home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / duplicatePreset.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.1 KB  |  224 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  April 30, 1997
  22. //  Author:         mm
  23. //
  24. //
  25.  
  26.  
  27. //
  28. //  Procedure Name:
  29. //      duplicatePreset
  30. //
  31. //  Description:
  32. //    Performs one or more duplications.
  33. //
  34. //  Return Value:
  35. //      None.
  36. //
  37. global proc duplicatePreset(
  38.     int $count,
  39.     int $copy,
  40.     int $group,
  41.     int $smart,
  42.     int $upstream,
  43.     int $inputConn,
  44.     int $renameChild,
  45.     float $transX, float $transY, float $transZ,
  46.     float $rotatX, float $rotatY, float $rotatZ,
  47.     float $scaleX, float $scaleY, float $scaleZ
  48. {
  49.     //    *NOTE*    This command is a complex script and therefore the command
  50.     //            echoing cannot be performed using evalEcho because 1) it is
  51.     //            too slow when duplicating large numbers of objects and
  52.     //            generates too many echoed commands 2) many of the commands
  53.     //            involve local variables so the echoed commands are incorrect
  54.     //
  55.     //            Therefore, this command uses print to generate its output
  56.     //            so you must ensure changes to the script are consistent with
  57.     //            the generated output.
  58.     //
  59.     string $cmd = "duplicate -rr";
  60.     string $objects[];
  61.     string $result[];
  62.  
  63.     if ($renameChild) {
  64.         $cmd += " -renameChildren";
  65.     }
  66.  
  67.     if (!$upstream && !$inputConn && !$copy)
  68.         $cmd = "instance";
  69.  
  70.     if ($upstream) {
  71.         //    Create duplicates of upstream nodes also.
  72.         //
  73.         $cmd += " -un";
  74.         for ($i = 0; $i < $count; ++$i) {
  75.             $result = eval($cmd);
  76.             for ($obj in $result) $objects[size($objects)] = $obj;
  77.         }
  78.         if ($count == 1) print($cmd+";");
  79.         else print("for ($i=0; $i<"+$count+"; ++$i) "+$cmd+";");
  80.     }
  81.     else if ($inputConn) {
  82.         //    Create duplicates of upstream connections (not nodes) also.
  83.         //
  84.         $cmd += " -ic";
  85.         for ($i = 0; $i < $count; ++$i) {
  86.             $result = eval($cmd);
  87.             for ($obj in $result) $objects[size($objects)] = $obj;
  88.         }
  89.         if ($count == 1) print($cmd+";");
  90.         else print("for ($i=0; $i<"+$count+"; ++$i) "+$cmd+";");
  91.     }
  92.     else if ($smart) {
  93.         //    Create duplicates
  94.         //
  95.         $cmd += " -st";
  96.         $result = eval($cmd);
  97.         for ($obj in $result) $objects[size($objects)] = $obj;
  98.         print($cmd+";");
  99.     }
  100.     else if ($count > 0) {
  101.         //    Create first duplicate
  102.         //
  103.         if ($count > 1) select `ls -sl`; // reset smart transform info
  104.  
  105.         $result = eval($cmd);
  106.         for ($obj in $result) $objects[size($objects)] = $obj;
  107.         print($cmd+";");
  108.  
  109.         if (size($objects) > 0) {
  110.             //    Transform it
  111.             //
  112.             if ($scaleX != 1.0 || $scaleY != 1.0 || $scaleZ != 1.0) {
  113.                 scale -r $scaleX $scaleY $scaleZ;
  114.                 print(" scale -r "+$scaleX+" "+$scaleY+" "+$scaleZ+";");
  115.             }
  116.  
  117.             if ($rotatX != 0.0 || $rotatY != 0.0 || $rotatZ != 0.0) {
  118.                 rotate -r $rotatX $rotatY $rotatZ;
  119.                 print(" rotate -r "+$rotatX+" "+$rotatY+" "+$rotatZ+";");
  120.             }
  121.  
  122.             if ($transX != 0.0 || $transY != 0.0 || $transZ != 0.0) {
  123.                 move -r $transX $transY $transZ;
  124.                 print(" move -r "+$transX+" "+$transY+" "+$transZ+";");
  125.             }
  126.  
  127.             //    Create remaining duplicates
  128.             //
  129.             $cmd += " -st";
  130.             for ($i = 1; $i < $count; ++$i) {
  131.                 $result = eval($cmd);
  132.                 for ($obj in $result) $objects[size($objects)] = $obj;
  133.             }
  134.             if ($count>1) print(" for ($i=1; $i<"+$count+"; ++$i) "+$cmd+";");
  135.         }
  136.     }
  137.     
  138.     if (size($objects) > 0) {
  139.         if ($group == 3) {
  140.             string $resultString;
  141.             $resultString = `group $objects`;
  142.  
  143.             //    Echo command and result
  144.             print(" group");
  145.             for ($obj in $objects) print(" "+$obj); print(";\n");
  146.             print("// Result: "+$resultString+" //\n");
  147.         } else if ($group == 2) {
  148.             string $objectsUnderWorld[];
  149.             string $parentableObjects[];
  150.             int $i = 0;
  151.             int $j = 0;
  152.             // filter out objects which are already under the world.
  153.             for ($obj in $objects) {
  154.                 string $parents[] = `listRelatives -p $obj`;
  155.                 if ( size($parents) == 0 ) {
  156.                     $objectsUnderWorld[$i] = $obj;
  157.                     ++$i;
  158.                 }
  159.                 else {
  160.                     $parentableObjects[$j] = $obj;
  161.                     ++$j;
  162.                 }
  163.             }
  164.  
  165.             // parent the objects which are not already under the world
  166.             if ( size($parentableObjects) > 0 ) {
  167.                 $result = `parent -w $parentableObjects`;
  168.             }
  169.  
  170.             // add the objects already under the world to the list of
  171.             // objects that were parented.
  172.             $i = size($result);
  173.             for ($obj in $objectsUnderWorld) {
  174.                 $result[$i] = $obj;
  175.                 ++$i;
  176.             }
  177.  
  178.             //    Echo parent command 
  179.             //
  180.             if ( size($parentableObjects) > 0 ) {
  181.                 print(" parent -w");
  182.                 for ($obj in $parentableObjects) {
  183.                     print(" "+$obj);
  184.                 }
  185.                 print(";\n");
  186.             }
  187.  
  188.             if ($count > 1) {
  189.                 select $result;
  190.  
  191.                 if (size($result) > 0) {
  192.                     //    Echo command and result
  193.                     print(" select");
  194.                     for ($obj in $result) print(" "+$obj); print(";");
  195.                 }
  196.             }
  197.             print("\n");
  198.  
  199.             string $resultStr = "// Result:";
  200.             for ($obj in $result) $resultStr = $resultStr+" "+$obj; 
  201.             $resultStr = $resultStr+" //\n";
  202.             print($resultStr);
  203.         } else {
  204.             if ($count > 1) {
  205.                 select $objects;
  206.  
  207.                 //    Echo command and result
  208.                 print(" select");
  209.                 for ($obj in $objects) print(" "+$obj); print(";");
  210.             }
  211.             print("\n");
  212.             
  213.             // print out the result, making sure it stays in the
  214.             // commandLine output area but using a single print.
  215.             //
  216.             string $resultStr = "// Result:";
  217.             for ($obj in $objects) $resultStr = $resultStr+" "+$obj; 
  218.             $resultStr = $resultStr+" //\n";
  219.             print $resultStr;
  220.         }
  221.     }
  222. }
  223.